﻿using FastColoredTextBoxNS;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

namespace Codestyle
{
    class AutoCodestyle : Style
    {

        public Brush ForeBrush { get; set; }
        public Brush BackgroundBrush { get; set; }
        public FontStyle FontStyle { get; set; }

        public override void Draw(Graphics gr, Point position, Range range)
        {
            //draw background  
            if (BackgroundBrush != null)
                gr.FillRectangle(BackgroundBrush, position.X, position.Y,
            (range.End.iChar - range.Start.iChar) *
            range.tb.CharWidth, range.tb.CharHeight);
            //draw chars  
            Font f = new Font(range.tb.Font, FontStyle);
            Line line = range.tb[range.Start.iLine];
            float dx = range.tb.CharWidth;
            float y = position.Y - 2f;
            float x = position.X - 2f;

            Brush foreBrush = this.ForeBrush ?? new SolidBrush(range.tb.ForeColor);

            for (int i = range.Start.iChar; i < range.End.iChar; i++)
            {
                //draw char  
                gr.DrawString(line[i].c.ToString(), f, foreBrush, x, y);
                x += dx;
            }
        }  
    }
}
